from typing import Optional

from pydantic import BaseModel, Field
from sqlalchemy import Column, String, BigInteger
from toollib.utils.now2timestamp_ import now2timestamp

from app.datatype import DeclBase, filter_fields



class MilvusIndex(DeclBase):
    __tablename__ = "milvus_index"

    #自增主键
    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="主键")
    #milvus_index
    milvus_index = Column(String(50), comment="milvus索引名称")
    name = Column(String(50), comment="中文名称")
    #描述
    file_num = Column(BigInteger, default = 0, nullable=True, comment="文件个数")
    description = Column(String(400), comment="描述")
    create_id = Column(String(20), comment="用户ID")
    update_id = Column(String(20), comment="修改ID")
    created_at = Column(BigInteger, default=now2timestamp, comment="创建时间")
    updated_at = Column(BigInteger, default=now2timestamp, onupdate=now2timestamp, comment="更新时间")
    #删除状态
    is_deleted = Column(BigInteger, default=0, comment="删除状态，0未删除，1已删除")
    type = Column(BigInteger, default=2, comment="1.私人知识库 2.公用知识库 3.通用知识库")
    create_id = Column(String(20), comment="用户ID")
    user_id = Column(String(20), comment="私人知识库用户ID")
class MilvusIndexDetailMdl(BaseModel):
    id: str = Field(...)
    # #
    name: str = None

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

#创建知识库
class MilvusIndexCreateMdl(BaseModel):
    milvus_index: str = Field('test', description="milvus索引名称(只能为英文)")
    name: str = Field('test', description="中文名称")
    file_num: int = Field(0, description="文件个数")
    description: str = Field("", description="描述")
    create_id: Optional[str]  = Field(None, description="用户ID")
    type: int = Field(default=2, description="1.私人知识库 2.公用知识库 3.通用知识库")
    user_id : Optional[str] = Field(default="", description="私人知识库用户ID")
#获取知识库列表
class MilvusIndexListMdl(BaseModel):
    id: int = Field(..., description="主键ID")
    milvus_index: str = Field(..., description="milvus索引名称")
    name: str = Field(..., description="中文名称")
    file_num: int = Field(0, description="文件个数")
    description: str = Field(..., description="描述")
    type: int = Field(default=2, description="1.私人知识库 2.公用知识库 3.通用知识库")
    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )
class MilvusIndexListFindMdl(BaseModel):
    find_name: Optional[str]  = Field(None, description="搜索名称")


    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

#通过milvus 索引名称删除知识库
class MilvusIndexDeleteMdl(BaseModel):
    id: int = Field(..., description="主键ID")
    milvus_index: str = Field(..., description="milvus索引名称")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

#通过id修改知识库
class MilvusIndexUpdateMdl(BaseModel):
    id: int = Field(..., description="主键ID")
    name: str = Field(None, description="中文名称")
    description: str = Field(None, description="描述")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )